package com.lly.songhigh.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.lly.songhigh.eventbus.MyEvent;

import de.greenrobot.event.EventBus;

/**
 * Created by 李新伟 on 15/11/3.
 */
public class MyReceiver extends BroadcastReceiver {
    public static final String NOTIFICATION_ITEM_BUTTON_LAST = "com.lly.notification.ServiceReceiver.last";// ----通知栏上一首按钮
    public static final String NOTIFICATION_ITEM_BUTTON_PLAY = "com.lly.notification.ServiceReceiver.play";// ----通知栏播放按钮
    public static final String NOTIFICATION_ITEM_BUTTON_NEXT = "com.lly.notification.ServiceReceiver.next";// ----通知栏下一首按钮
    public static final String NOTIFICATION_ITEM_BUTTON_DELETE = "com.lly.notification.ServiceReceiver.delete";// ----通知栏清楚按钮
    public static int status = 1; // 1 代表播放  2 代表暂停

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(NOTIFICATION_ITEM_BUTTON_LAST)) {// ----通知栏播放按钮响应事件
            EventBus.getDefault().post(new MyEvent.PlayControl(7));
        } else if (action.equals(NOTIFICATION_ITEM_BUTTON_PLAY)) {// ----通知栏播放按钮响应事件
            switch (status) {
                case 1:
                    EventBus.getDefault().post(new MyEvent.MediaPlay(2));
                    status = 2;
                    break;
                case 2:
                    EventBus.getDefault().post(new MyEvent.MediaPlay(3));
                    status = 1;
                    break;
            }
        } else if (action.equals(NOTIFICATION_ITEM_BUTTON_NEXT)) {// ----通知栏下一首按钮响应事件
            EventBus.getDefault().post(new MyEvent.PlayControl(6));
        } else if (action.equals(NOTIFICATION_ITEM_BUTTON_DELETE)) {
            EventBus.getDefault().post(new MyEvent.CleanNotification(true));
        }
    }
}
